/**
 * Created by Administrator on 2017/7/7 0007.
 */
require(["jquery","bbcare","scprit/department/vm/queueManagement/queueManagement-data.js"],function($,$bb,$tpl) {
    var URL = $bb.baseUrl("department") + "followup/service";
    $bb.ajax({
        url: URL + "/queue/followQueueListQuery",
        type: "post",
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        data: JSON.stringify({
            data: {
                page:1
            }
        }),
        success: function (data) {
            if(data.success){
                var res=$tpl.dataDeal(data.data.rows);
                for(var i=0;i<res.length;i++){
                    getDoctorList(res[i]);
                }
            }
        }
    });
    function getDoctorList(obj){
        $bb.ajax({
            url: URL + "/queue/authority/teams",
            type: "post",
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            data: JSON.stringify({
                data: {
                    queueId:obj.id
                }
            }),
            success: function (data) {
                if(data.success){
                    obj.doctorTotal=data.data.length;
                    if(obj.doctorTotal>3){
                        obj.doctorRows=data.data.substr(0,3);
                    }else{
                        obj.doctorRows=data.data;
                    }

                    $tpl.queuelist({"id":"#queueList","data":obj});
                    $("#queueList>div").click(function(){
                        var queueId=$(this).attr("queueId");
                        $bb.openPage('createQueue',queueId);
                    });
                }
            }
        });
    }
    var newQueue = function(){
        $("div").removeData("params");//清除缓存；
        $bb.openPage("createQueue");
    }
    var topbars = [
        {
            "icon":"fa fa-plus",
            "name":"新建队列",
            "callback":newQueue,
            "params":{"dom":"#resultInfo"}
        }
    ];
    $bb.toolbar(topbars);
})

